﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using MyFloridaHouse.DataAccess.Extensions;
using MyFloridaHouse.libSvDTO;

namespace MyFloridaHouse.DataAccess
{
    public partial class DAL_CensusData
    {

        /// <summary>
        /// Gets names for any regions IDs in a list.
        /// </summary>
        /// <param name="targetLayerID">The itargetlayerID.</param>
        /// <param name="iRegionIDList">The iregionID list.</param>
        /// <param name="iSourceLayerID">The isourcelayerID.</param>
        /// <param name="iDictionaryIDList">The idictionaryID list.</param>
        /// <returns>List of <see cref="RegionDataDTO"/></returns>
        /// <remarks>SPROC: usp_GetRegionsDataInView</remarks>
        public List<RegionDataDTO> GetRegionsListName(int targetLayerID, List<int> regionIDList, int dictionaryID)
        {
            List<RegionDataDTO> itemList = new List<RegionDataDTO>();

            string regionIDListStr = string.Join(",", regionIDList);
            string storedProcedureName = "usp_tl10GetRegionsName10";
            using (SqlConnection db = Connect())
            {
                SqlCommand StoredProcedureCommand = new SqlCommand(storedProcedureName, db);
                StoredProcedureCommand.CommandType = CommandType.StoredProcedure;
                SqlParameter dataPartIDParm = StoredProcedureCommand.Parameters.AddWithValue("targetLayerID", targetLayerID);
                dataPartIDParm.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm2 = StoredProcedureCommand.Parameters.AddWithValue("regionIDList", regionIDListStr);
                dataPartIDParm2.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm3 = StoredProcedureCommand.Parameters.AddWithValue("dictionaryID", dictionaryID);
                dataPartIDParm3.Direction = ParameterDirection.Input;

                db.Open();
                using (SqlDataReader rdr = StoredProcedureCommand.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        itemList.Add(RegionDataDTODataContract.DataContract(rdr));
                    }
                }
            }


            return itemList;
        }

    }
}
